import React from 'react';
import {Link} from 'dva/router';

import styles from './rbutton.css';
import {Redirect} from 'react-router-dom';
import FloatBtn from "../pic/FloatBtn";
import FaHome from 'react-icons/lib/fa/home';
import FaLeft from 'react-icons/lib/fa/angle-double-left';
import FaDownload from 'react-icons/lib/fa/download';
import getThemeColor from "../../utils/themeutil";
import getParams from "../../utils/pathutil";

class RenderButton extends React.Component {
  state = {
    hover: false,
    redirect: false,
    returnToHome: true,
    from: '/',
  };

  constructor(props) {
    super(props);
    // 根据url参数，获取poetryId, 然后向后端发起请求，获取对应的数据
    let from = getParams("from");
    if (from && from !== '/') {
      this.state.from = from;
      this.state.returnToHome = false;
    }
  }


  toHome = () => {
    this.setState({
      redirect: true,
    })
  };

  render() {
    if (this.state.redirect) {
      console.log("redirect!");
      return (
        <Redirect push to={"/"}/>
      )
    }

    return (
      <div className={styles["btn-container"]}>
        {/*<button className={styles["home-btn"]} onClick={this.toHome}>*/}
        {/*主页*/}
        {/*</button>*/}

        <Link to={this.state.from}>
          <FloatBtn children={this.state.returnToHome ? <FaHome/> : <FaLeft/>}
            // clickFunc={this.toHome}
                    btnStyle={{backgroundColor: getThemeColor()}}/>
        </Link>
        <FloatBtn children={<FaDownload/>}
                  clickFunc={this.props.render}
                  btnStyle={{backgroundColor: getThemeColor()}}/>

        {/*<button className={styles["render-btn"] + ' ' + (this.state.hover ? styles["render-btn-hover"] : ' ')}*/}
        {/*onClick={this.props.render}>*/}
        {/*存*/}
        {/*</button>*/}
      </div>);
  }
}

export default RenderButton;
